#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=15,inf=1e18;
int n,f[N],a[N],de[N],b[N],dis[N],wyt[N],d[N],len;
vector <int> e[N];
void dfs(int u){
	if(!e[u].size())wyt[++len]=u;
	for(auto v:e[u]){
		de[v]=de[u]+1,dis[v]=dis[u]+a[v],dfs(v);
	}
}
int vis[N],c[N];
int lca(int x,int y){
	if(de[x]<de[y])swap(x,y);
	while(de[x]>de[y])x=f[x];
	if(x==y)return x;
	while(f[x]!=f[y])x=f[x],y=f[y];
	return f[x];
}
bool check(){
	for(int i = 1;i <= n;i++)d[i]=0;
	for(int i = 2;i <= len+2;i++){
		int x=b[i-1],y=b[i],lca1=lca(x,y);
		while(x!=lca1)d[x]++,x=f[x];
		while(y!=lca1)d[y]++,y=f[y];
	}
	for(int i = 2;i <= n;i++)if(d[i]!=2)return false;
	return true;
}int ans=inf;
int calc(int x,int y){
	int lca1=lca(x,y);
	return dis[x]+dis[y]-dis[lca1]*2ll;
}
void dfs1(int cnt){
	if(cnt==len+2){
		if(check()){
			int maxn=0;
			for(int i = 3;i <= len+1;i++)maxn=max(maxn,calc(b[i-1],b[i]));
			ans=min(ans,maxn);
		}	
		return;
	}
	for(int i = 1;i <= len;i++){
		if(!vis[i]){
			vis[i]=1;b[cnt]=wyt[i];
			dfs1(cnt+1);
			vis[i]=0;
		}
	}
}
signed main(){
	freopen("trip.in","r",stdin);
	freopen("trip.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i = 2;i <= n;i++)cin >> f[i] >> a[i],e[f[i]].push_back(i);
	b[1]=1,b[len+2]=1;dfs(1);dfs1(2);
	cout << ans;
	return 0;
}

